import java.util.ArrayList;
import java.util.List;

public class test1 {
    public static int reace(int n){
        int temp=0;
        while(n!=0){
            temp=temp+(n%10)*(n%10);
            n=n/10;
        }
        return temp;
    }
    public boolean isHappy1(int n) {
        //双指针思路
        int x=reace(n);
        int y=reace(reace(n));
        while(x!=y){
            x=reace(x);
            y=reace(reace(y));
        }
  return x==1;
    }
    public boolean isHappy2(int n) {
        //利用集合
        ArrayList<Integer> list=new ArrayList<>();
        while(n!=1){
            list.add(n);
            n=reace(n);
            if(list.contains(n)){
                return false;
            }
        }
        return true;
    }
}
